﻿using System.Windows.Controls;
using System.Windows.Navigation;
using Infragistics.Controls.Charts;
using StartupSolution.Models;
using StartupSolution.ViewModel;

namespace StartupSolution.Views.Charts
{
    public partial class DrillDown : Page
    {
        public DrillDown()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            LayoutRoot.DataContext = new DrillDownViewModel();
        }

        private void companiesChart_SeriesMouseLeftButtonDown(object sender, DataChartMouseButtonEventArgs e)
        {
            //This snippet gets the data context of the selected bar and passes it to the second chart.
            CompanyModel selectedItem = e.Item as CompanyModel;
            if(selectedItem != null)
            {
                productsChart.DataContext = selectedItem.Products;
                productsChart.Series[0].Title = "Products Revenue for " + selectedItem.Name;
            }
        }

        private void productsChart_SeriesMouseLeftButtonDown(object sender, DataChartMouseButtonEventArgs e)
        {
            //This snippet gets the data context of the selected bar from the second chart
            //and passes it to the third chart.
            ProductModel selectedItem = e.Item as ProductModel;
            if(selectedItem != null)
            {
                salesChart.DataContext = selectedItem.Sales;
                salesChart.Series[0].Title = "Product sales for " + selectedItem.Name;
            }
        }
    }
}
